import java.util.Stack;

public class demo2 {
    public String decodeString(String s) {
        Stack<Integer>stack=new Stack<>();
        StringBuilder ret=new StringBuilder();
        char []arr=s.toCharArray();
        int i=0;
        int n=s.length();
        while(i<n){
            if(arr[i]>='0'&&arr[i]<='9'){
                int sum=0;
                while(arr[i]>='0'&&arr[i]<='9'){
                    sum=sum*10+arr[i]-'0';
                    i++;
                }
                stack.add(sum);
            }
            else if(arr[i]=='['){
                StringBuilder stringBuilder=new StringBuilder();
                while (arr[i]!=']'){
                    if(arr[i]!='[')stringBuilder.append(arr[i]);
                    i++;
                }
                int x=0;
                if(!stack.isEmpty())x=stack.pop();
                while (x>0){
                    ret.append(stringBuilder);
                    x--;
                }
            }else {
                if(arr[i]!=']') ret.append(arr[i]);
                i++;}
        }
        return ret.toString();
    }
}
